package play;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

import util.Settings;

/**
 * Handles dialog in the game.
 * @author VincentLy
 */
public class Dialog extends BasicGameState{
	
	private int line = 0;
	
	public Dialog(){super();}

	/**
	 * No initialization needed here yet.
	 * @author VincentLy
	 */
	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {}

	/**
	 * Checks to see if user is advancing/finishing dialog.
	 * @author VincentLy
	 */
	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		Input i = gc.getInput();
		if(i.isKeyPressed(Input.KEY_SPACE)){
			line++;
			if(line==Settings.dialog.length){		
				line = 0;
				sbg.getState(Settings.wID).init(gc,sbg);
				sbg.enterState(Settings.wID);
			}	
		}	
	}
	
	/**
	 * Draws the dialog onto the screen.
	 * @author VincentLy
	 */
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		g.setAntiAlias(true);
		g.setBackground(Color.black);
		g.drawImage(Settings.pause,0,0);
		g.setLineWidth(1);
		g.drawString(Settings.dialog[line],(Settings.screenX-g.getFont().getWidth(Settings.dialog[line]))/2,250);
		g.drawString("Press space to continue...",(Settings.screenX-g.getFont().getWidth("Press space to continue..."))/2,400);
	}

	/**
	 * @return id
	 * @author VincentLy
	 */
	public int getID() {return Settings.diID;}
}